//
//  ServiceVC.swift
//  kxf
//
//  Created by Mac on 2024/3/19.
//

import Foundation
import UIKit


class ServiceVC : WHBaseViewVC {
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        initUI()
        sendServiceRequest()
    }
    lazy var bgWhiteImgView : UIImageView = {
        let img = UIImageView()
        img.setImgLocal(imgName: "mine_qrcode_bg")
        img.isUserInteractionEnabled = true
        
        return img
    }()
    lazy var qrCodeImgView : UIImageView = {
        let img = UIImageView()
//        img.setImgLocal(imgName: "service_img")
        return img
    }()
    
    lazy var codeLabel : UILabel = {
        let lab = UILabel()
        lab.backgroundColor = WHColor_16(colorStr: "F8F8F8")
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 20, weight: .regular)
        lab.textAlignment = .center
        lab.layer.cornerRadius = kFitWidth(24)
        lab.clipsToBounds = true
        lab.adjustsFontSizeToFitWidth = true
        lab.text = "打开微信扫码关注"
        return lab
    }()
    lazy var serviceWhiteView : UIView = {
        let vi = UIView()
        vi.backgroundColor = .white
        vi.layer.cornerRadius = kFitWidth(8)
        vi.clipsToBounds = true
        
        
        return vi
    }()
    lazy var serviceImgView : UIImageView = {
        let img = UIImageView()
//        img.setImgLocal(imgName: "service_icon")
        return img
    }()
    lazy var serviceTimeLabel : UILabel = {
        let lab = UILabel()
        lab.text = "客服在线时间：9:00——18:00"
        lab.textColor = .black
        lab.font = .systemFont(ofSize: 14, weight: .medium)
        
        return lab
    }()
    lazy var servicePhoneLabel : UILabel = {
        let lab = UILabel()
        lab.text = "客服热线：400 116 2322"
        lab.font = .systemFont(ofSize: 14, weight: .regular)
        lab.textColor = .COLOR_TEXT_BLACK666
        
        return lab
    }()
}

extension ServiceVC{
    func initUI() {
        initNavi(titleStr: "帮助中心")
        
        view.addSubview(scrollView)
        scrollView.frame = CGRect.init(x: 0, y: getNavigationBarHeight(), width: SCREEN_WIDHT, height: SCREEN_HEIGHT - getNavigationBarHeight())
        scrollView.backgroundColor = WHColorWithAlpha(colorStr: "F10E0E", alpha: 0.09)
        
        scrollView.addSubview(bgWhiteImgView)
        bgWhiteImgView.addSubview(codeLabel)
        bgWhiteImgView.addSubview(qrCodeImgView)
        
        scrollView.addSubview(serviceWhiteView)
        serviceWhiteView.addSubview(serviceImgView)
        serviceWhiteView.addSubview(serviceTimeLabel)
        serviceWhiteView.addSubview(servicePhoneLabel)
        
        setConstrait()
    }
    func setConstrait() {
        bgWhiteImgView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(kFitWidth(22))
            make.width.equalTo(kFitWidth(343))
            make.height.equalTo(kFitWidth(406))
        }
        qrCodeImgView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(kFitWidth(138))
            make.width.height.equalTo(kFitWidth(240))
        }
        codeLabel.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(kFitWidth(45))
            make.width.equalTo(kFitWidth(220))
            make.height.equalTo(kFitWidth(48))
        }
        serviceWhiteView.snp.makeConstraints { make in
            make.centerX.lessThanOrEqualToSuperview()
            make.top.equalTo(bgWhiteImgView.snp.bottom).offset(kFitWidth(35))
            make.width.equalTo(kFitWidth(343))
            make.height.equalTo(kFitWidth(99))
        }
        serviceImgView.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(22))
            make.centerY.lessThanOrEqualToSuperview()
            make.width.height.equalTo(kFitWidth(62))
        }
        serviceTimeLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(124))
            make.top.equalTo(kFitWidth(30))
        }
        servicePhoneLabel.snp.makeConstraints { make in
            make.left.equalTo(kFitWidth(124))
            make.bottom.equalTo(kFitWidth(-16))
        }
    }
}

extension ServiceVC{
    func sendServiceRequest()  {
        WHNetworkUtil.shareManager().POST(urlString: URL_Get_ServicePhone, parameters: nil) { responseObject in
            DLLog(message: "\(responseObject)")
            
            let dataObj = responseObject["data"]as? NSDictionary ?? [:]
            
            self.qrCodeImgView.setImgUrl(urlString: dataObj["serviceCodeUrl"]as? String ?? "")
            self.serviceImgView.setImgUrl(urlString: dataObj["serviceCodeUrl"]as? String ?? "")
            self.serviceTimeLabel.text = "客服在线时间：\(dataObj["serviceTime"]as? String ?? "")"
            self.servicePhoneLabel.text = "客服热线：\(dataObj["servicePhone"]as? String ?? "")"
        }
    }
}
